package javango.db;

public class SimplePaginator<T> extends AbstractPaginator<T> {

	final int count;
	
	public SimplePaginator(int perPage, int count) {
		super(perPage);
		this.count = count;
	}

	public SimplePaginator(int perPage, int orphans, int count) {
		super(perPage,orphans);
		this.count = count;
	}
	
	public int getCount() {
		return count;
	}

	public Page<T> getPage(int number) {
		number = this.validateNumber(number);
		int bottom = (number - 1) * this.perPage;
		int top = bottom + this.perPage;
		if (top + this.getOrphans() >= this.getCount()) {
			top = this.getCount();
		}
		return new SimplePage<T>(number, this);
	}

}
